using System;
using System.Collections.Generic;
using System.Threading;

namespace ns20
{
	internal class Class179<T, U>
	{
		private readonly object object_0 = new object();

		private Dictionary<T, U> dictionary_0;

		private readonly Func<T, U> func_0;

		public Class179(Func<T, U> creator)
		{
			if (creator == null)
			{
				throw new ArgumentNullException("creator");
			}
			func_0 = creator;
			dictionary_0 = new Dictionary<T, U>();
		}

		public U method_0(T gparam_0)
		{
			if (!dictionary_0.TryGetValue(gparam_0, out var value))
			{
				return method_1(gparam_0);
			}
			return value;
		}

		private U method_1(T gparam_0)
		{
			U val = func_0(gparam_0);
			lock (object_0)
			{
				if (dictionary_0 == null)
				{
					dictionary_0 = new Dictionary<T, U>();
					dictionary_0[gparam_0] = val;
				}
				else
				{
					if (dictionary_0.TryGetValue(gparam_0, out var value))
					{
						return value;
					}
					Dictionary<T, U> dictionary = new Dictionary<T, U>(dictionary_0);
					dictionary[gparam_0] = val;
					Thread.MemoryBarrier();
					dictionary_0 = dictionary;
				}
				return val;
			}
		}
	}
}
